<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="关键字" prop="keyword" v-if="isYingjian">
        <el-input
          v-model="queryParams.keyword"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应标题" prop="supplyTitle" v-if="!isYingjian">
        <el-input
          v-model="queryParams.supplyTitle"
          placeholder="请输入供应标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="城市名" prop="cityName" v-if="!isYingjian">
        <el-select
          v-model="queryParams.cityName"
          placeholder="请选择城市名"
          filterable
          clearable
        >
          <el-option
            v-for="option in allCityList"
            :key="option.code"
            :label="option.completeName"
            :value="option.name"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="公司" prop="companyId">
        <el-select
          v-model="queryParams.companyId"
          placeholder="请选择公司"
          filterable
          clearable
        >
          <el-option
            v-for="option in companyList"
            :key="option.id"
            :label="option.companyName"
            :value="option.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="供电方式" prop="framePowerWay" v-if="isJigui">
        <el-select
          v-model="queryParams.framePowerWay"
          placeholder="请选择机柜供电方式"
          clearable
        >
          <el-option
            v-for="dict in dict.type.power_way"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="运营商" prop="bwOperator" v-if="isDaikuan">
        <el-select
          v-model="queryParams.bwOperator"
          placeholder="请选择运营商"
          clearable
        >
          <el-option
            v-for="dict in dict.type.operator"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="路由类型" prop="bwRouteType" v-if="isDaikuan">
        <el-select
          v-model="queryParams.bwRouteType"
          placeholder="请选择路由类型"
          clearable
        >
          <el-option
            v-for="dict in dict.type.route_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="计算资源" prop="gpuResource" v-if="isSuanli">
        <el-select
          v-model="queryParams.gpuResource"
          placeholder="请选择计算资源"
          clearable
        >
          <el-option
            v-for="dict in dict.type.gpu_resource_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="网络架构" prop="gpuNet" v-if="isSuanli">
        <el-input
          v-model="queryParams.gpuNet"
          placeholder="请输入网络架构"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="适用场景" prop="gpuOccasion" v-if="isSuanli">
        <el-input
          v-model="queryParams.gpuOccasion"
          placeholder="请输入适用场景"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卡类型" prop="gpuType" v-if="isSuanli">
        <el-select
          v-model="queryParams.gpuType"
          placeholder="请选择卡类型"
          clearable
        >
          <el-option
            v-for="dict in dict.type.supply_gpu_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button
        >
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="danger"-->
      <!--          plain-->
      <!--          icon="el-icon-delete"-->
      <!--          size="mini"-->
      <!--          :disabled="multiple"-->
      <!--          @click="handleDelete"-->
      <!--          >删除</el-button-->
      <!--        >-->
      <!--      </el-col>-->
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="warning"-->
      <!--          plain-->
      <!--          icon="el-icon-download"-->
      <!--          size="mini"-->
      <!--          @click="handleExport"-->
      <!--          >导出</el-button-->
      <!--        >-->
      <!--      </el-col>-->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="supplyList"
      @selection-change="handleSelectionChange"
    >
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="ID" align="center" prop="id" width="50" />

      <el-table-column
        label="供应标题"
        align="center"
        prop="supplyTitle"
        width="180"
        show-overflow-tooltip
      />
      <el-table-column label="状态" align="center" prop="status" width="100">
        <template slot-scope="{ row }">
          <span v-if="row.status === -1">未审核</span>
          <span v-else-if="row.status === -2">已驳回</span>
          <template v-else>
            <el-switch
              :value="row.status"
              :active-value="1"
              :inactive-value="0"
              @change="toggleStatus(row)"
            ></el-switch>
            <span>{{ row.status ? "上架" : "下架" }}</span>
          </template>
        </template>
      </el-table-column>
      <el-table-column
        label="推荐状态"
        align="center"
        prop="recommendStatus"
        width="120px"
      >
        <template #default="{ row }">
          <el-switch
            :value="row.recommendStatus"
            :active-value="1"
            :inactive-value="0"
            @change="handleToggleIsTop(row)"
          ></el-switch>
          <span>{{ row.recommendStatus ? "" : "" }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="供应描述"
        align="center"
        prop="supplyDesc"
        width="180"
        show-overflow-tooltip
        v-if="!isYingjian"
      />
      <el-table-column
        label="联系人"
        align="center"
        width="80"
        show-overflow-tooltip
        v-if="!isYingjian"
      >
        <template slot-scope="scope">
          {{scope.row.supplyUserInfo.nickName}}
        </template>
      </el-table-column>
      <el-table-column
        label="联系方式"
        align="center"
        width="120"
        show-overflow-tooltip
        v-if="!isYingjian"
      >
        <template slot-scope="scope">
          {{scope.row.supplyUserInfo.phonenumber}}
        </template>
      </el-table-column>
      <el-table-column
        label="省"
        align="center"
        prop="provinceName"
        width="80"
      />
      <el-table-column
        label="市"
        align="center"
        prop="cityName"
        width="80"
      />
      <el-table-column
        label="节点名"
        align="center"
        prop="supplyNodeName"
        width="80"
        show-overflow-tooltip
        v-if="!isYingjian"
      />
      <el-table-column
        label="创建人"
        align="center"
        prop="createBy"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        label="创建人公司"
        align="center"
        show-overflow-tooltip
        prop="supplyUserInfo.companyName"
        width="120"
      />
      <!-- 机柜字段 -->
      <template v-if="isJigui">
        <el-table-column
          label="供电方式"
          align="center"
          prop="framePowerWay"
          width="100"
        >
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.power_way"
              :value="scope.row.framePowerWay"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="机柜功率(KW)"
          align="center"
          prop="framePower"
          width="120"
        />
        <el-table-column
          label="机柜高度"
          align="center"
          prop="frameHeight"
          width="100"
        />
        <el-table-column
          label="单价"
          align="center"
          prop="framePrice"
          width="80"
        />
        <el-table-column label="单位" align="center" width="100">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.frame_price_unit"
              :value="scope.row.priceUnit"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="可租数量"
          align="center"
          prop="supplyNum"
          width="100"
        />
      </template>
      <!-- 带宽字段 -->
      <template v-else-if="isDaikuan">
        <el-table-column
          label="运营商"
          align="center"
          prop="bwOperator"
          width="80"
        >
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.operator"
              :value="scope.row.bwOperator"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="路由类型"
          align="center"
          prop="bwRouteType"
          width="100"
        >
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.route_type"
              :value="scope.row.bwRouteType"
            />
          </template>
        </el-table-column>
        <el-table-column label="单位" align="center" width="100">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.bw_price_unit"
              :value="scope.row.priceUnit"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="带宽价格"
          align="center"
          prop="bwBandwidthPrice"
          width="100"
        />
        <el-table-column
          label="带宽可租数量(G)"
          align="center"
          prop="bwBandwidthNum"
          width="100"
        />
        <el-table-column
          label="IP价格"
          align="center"
          prop="bwIpPrice"
          width="100"
        />
        <el-table-column
          label="IP可租数量(G)"
          align="center"
          prop="bwIpNum"
          width="100"
        />
      </template>
      <!-- 算力字段 -->
      <template v-else-if="isSuanli">
        <el-table-column
          label="计费模式"
          align="center"
          prop="gpuAbilityType"
          width="100"
        >
          <template slot-scope="{ row }">
            {{ row.gpuAbilityType === 1 ? "算力包月" : "卡时计费" }}
          </template>
        </el-table-column>
        <el-table-column
          label="可租算力(PFLOPS)"
          align="center"
          prop="gpuApplyPflops"
        />
        <el-table-column
          label="计算资源"
          align="center"
          prop="gpuResource"
          width="100"
        />
        <el-table-column
          label="网络架构"
          align="center"
          prop="gpuNet"
          width="100"
        />
        <el-table-column
          label="可租数量"
          align="center"
          prop="gpuNum"
          width="80"
        />
        <el-table-column
          label="单价"
          align="center"
          prop="gpuPrice"
          width="80"
        />
        <el-table-column label="单位" align="center" width="100">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.gpu_price_unit"
              :value="scope.row.priceUnit"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="卡类型"
          align="center"
          prop="gpuType"
          width="80"
        >
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.supply_gpu_type"
              :value="scope.row.gpuType"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="适用场景"
          align="center"
          prop="gpuOccasion"
          width="100"
        />
      </template>
      <!-- 硬件字段 -->
      <template v-else-if="isYingjian">
        <el-table-column
          label="配置参数"
          align="center"
          prop="supplyDesc"
          width="180"
          show-overflow-tooltip
        />
        <el-table-column
          label="品牌"
          align="center"
          prop="brandName"
          width="180"
          show-overflow-tooltip
        />
        <el-table-column
          label="型号"
          align="center"
          prop="modelName"
          width="180"
          show-overflow-tooltip
        />
        <el-table-column
          label="货源性质"
          align="center"
          prop="goodsType"
          width="100"
          :formatter="formatGoodsType"
        />
        <el-table-column
          label="单价"
          align="center"
          prop="goodsPrice"
          width="180"
          show-overflow-tooltip
        />
        <el-table-column
          label="销售数量"
          align="center"
          prop="goodsNumber"
          width="80"
          show-overflow-tooltip
        />
        <el-table-column label="单位" align="center" width="100">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.goods_price_unit"
              :value="scope.row.priceUnit"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="联系人"
          align="center"
          prop="contactUser"
          width="180"
          show-overflow-tooltip
        />
        <el-table-column
          label="联系电话"
          align="center"
          prop="contactUserMobile"
          width="180"
          show-overflow-tooltip
        />
        <el-table-column
          label="到货时间"
          align="center"
          prop="arriveTime"
          width="180"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span v-if="scope.row.goodsType === 2">{{ scope.row.arriveTime || '-' }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column
          label="信息过期时间"
          align="center"
          prop="expireTime"
          width="180"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span v-if="scope.row.goodsType === 1">{{ scope.row.expireTime || '-' }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column
          label="交付地点"
          align="center"
          prop="goodsAddress"
          width="180"
          show-overflow-tooltip
        />
        <el-table-column
          label="信息大图"
          align="center"
          prop="infoPicUrl"
          width="100"
        >
          <template slot-scope="scope">
            <image-preview
              v-if="scope.row.infoPicUrl"
              :src="scope.row.infoPicUrl"
              :width="50"
              :height="50"
            />
            <span v-else>无</span>
          </template>
        </el-table-column>
      </template>

      <template v-if="!isYingjian">
        <el-table-column label="可租时间" align="center" width="240">
          <template slot-scope="scope">
          <span>{{ parseTime(scope.row.supplyBegin, "{y}-{m}-{d}") }}</span
          >~
            <span>{{ parseTime(scope.row.supplyEnd, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>

        <el-table-column
          label="上架截止时间"
          align="center"
          prop="deadTime"
          width="120"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.deadTime, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
      </template>
      <el-table-column
        label="备注"
        align="center"
        prop="remark"
        width="130px"
        show-overflow-tooltip
      />
      <el-table-column label="创建时间" prop="createTime" align="center" width="180" />
      <el-table-column
        label="操作"
        align="center"
        fixed="right"
        width="140"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleToggleIsTop(scope.row)"
          >{{ scope.row.recommendStatus ? "取消置顶" : "置顶" }}</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button
          >
          <!--          <el-button-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            icon="el-icon-delete"-->
          <!--            @click="handleDelete(scope.row)"-->
          <!--            >删除</el-button-->
          <!--          >-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改供应信息对话框 -->
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
      :visible.sync="open"
      width="700px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="供应标题" prop="supplyTitle">
          <el-input v-model="form.supplyTitle" placeholder="请输入供应标题" />
        </el-form-item>
        <el-form-item label="供应描述" prop="supplyDesc" v-if="!isYingjian">
          <el-input
            v-model="form.supplyDesc"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="省市" prop="provinceArr">
          <el-cascader
            style="width: 100%"
            v-model="form.provinceArr"
            :options="provinceOptions"
            :props="cascaderProps"
          ></el-cascader>
        </el-form-item>
        <template v-if="isJigui">
          <el-form-item label="供电方式" prop="framePowerWay">
            <el-select
              v-model="form.framePowerWay"
              placeholder="请选择供电方式"
            >
              <el-option
                v-for="dict in dict.type.power_way"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="机柜功率(KW)" prop="framePower">
            <el-input
              v-model="form.framePower"
              placeholder="请输入机柜功率(KW)"
            />
          </el-form-item>
          <el-form-item label="机柜高度" prop="frameHeight">
            <el-input v-model="form.frameHeight" placeholder="请输入机柜高度" />
          </el-form-item>
          <el-form-item label="单位" prop="priceUnit">
            <el-select v-model="form.priceUnit" placeholder="请选择单位">
              <el-option
                v-for="dict in dict.type.frame_price_unit"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="单价" prop="framePrice">
            <el-input v-model="form.framePrice" placeholder="请输入单价" oninput="value=value.replace(/[^0-9.]/g,'')" />
          </el-form-item>
          <el-form-item label="可租数量" prop="supplyNum">
            <el-input v-model="form.supplyNum" placeholder="请输入可租数量" />
          </el-form-item>
        </template>
        <template v-else-if="isDaikuan">
          <el-form-item label="运营商" prop="bwOperator">
            <el-select v-model="form.bwOperator" placeholder="请选择运营商">
              <el-option
                v-for="dict in dict.type.operator"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="路由类型" prop="bwRouteType">
            <el-select v-model="form.bwRouteType" placeholder="请选择路由类型">
              <el-option
                v-for="dict in dict.type.route_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="单位" prop="priceUnit">
            <el-select v-model="form.priceUnit" placeholder="请选择单位">
              <el-option
                v-for="dict in dict.type.bw_price_unit"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="带宽价格" prop="bwBandwidthPrice">
            <el-input
              v-model="form.bwBandwidthPrice"
              placeholder="请输入带宽价格"
            />
          </el-form-item>
          <el-form-item label="带宽可租数量(G)" prop="bwBandwidthNum">
            <el-input
              v-model="form.bwBandwidthNum"
              placeholder="请输入带宽数量"
            />
          </el-form-item>
          <el-form-item label="IP价格" prop="bwIpPrice">
            <el-input v-model="form.bwIpPrice" placeholder="请输入IP价格" />
          </el-form-item>
          <el-form-item label="IP可租数量(G)" prop="bwIpNum">
            <el-input v-model="form.bwIpNum" placeholder="请输入可租数量" />
          </el-form-item>
        </template>
        <template v-else-if="isSuanli">
          <el-form-item label="可租算力(PFLOPS)" prop="gpuApplyPflops">
            <el-input
              v-model="form.gpuApplyPflops"
              placeholder="请输入可租算力(PFLOPS)"
            />
          </el-form-item>
          <el-form-item label="计算资源" prop="gpuResource">
            <el-select
              v-model="form.gpuResource"
              placeholder="请选择算力-计算资源"
              clearable
            >
              <el-option
                v-for="dict in dict.type.gpu_resource_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="网络架构" prop="gpuNet">
            <el-input v-model="form.gpuNet" placeholder="请输入网络架构" />
          </el-form-item>
          <el-form-item label="计费模式" prop="gpuAbilityType">
            <el-select
              v-model="form.gpuAbilityType"
              placeholder="请选择计费模式"
              clearable
            >
              <el-option label="算力包月" :value="1" />
              <el-option label="卡时计费" :value="2" />
            </el-select>
          </el-form-item>
          <el-form-item label="可租数量" prop="gpuNum">
            <el-input v-model="form.gpuNum" placeholder="请输入可租数量" />
          </el-form-item>
          <el-form-item label="单价" prop="gpuPrice">
            <el-input v-model="form.gpuPrice" placeholder="请输入单价" oninput="value=value.replace(/[^0-9.]/g,'')" />
          </el-form-item>
          <el-form-item label="单位" prop="priceUnit">
            <el-select v-model="form.priceUnit" placeholder="请选择单位">
              <el-option
                v-for="dict in dict.type.gpu_price_unit"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="卡类型" prop="gpuType">
            <el-select
              v-model="form.gpuType"
              placeholder="请选择卡类型"
              clearable
            >
              <el-option
                v-for="dict in dict.type.supply_gpu_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="适用场景" prop="gpuOccasion">
            <el-input v-model="form.gpuOccasion" placeholder="请输入适用场景" />
          </el-form-item>
        </template>
        <template v-else-if="isYingjian">
          <el-form-item label="配置参数" prop="supplyDesc">
            <el-input
              v-model="form.supplyDesc"
              type="textarea"
              placeholder="请输入内容"
            />
          </el-form-item>
          <el-form-item label="货源性质" prop="goodsType">
            <el-radio-group v-model="form.goodsType">
              <el-radio :label="1">现货</el-radio>
              <el-radio :label="2">期货</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="品牌" prop="modelName">
            <el-input v-model="form.brandName" placeholder="请输入品牌" />
          </el-form-item>
          <el-form-item label="型号" prop="modelName">
            <el-input v-model="form.modelName" placeholder="请输入型号" />
          </el-form-item>
          <el-form-item label="单价" prop="goodsPrice">
            <el-input
              v-model="form.goodsPrice"
              oninput="value=value.replace(/[^0-9.]/g,'')"
              placeholder="请输入单价"
              type="number"
            />
          </el-form-item>
          <el-form-item label="单位" prop="priceUnit">
            <el-select v-model="form.priceUnit" placeholder="请选择单位">
              <el-option
                v-for="dict in dict.type.goods_price_unit"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="销售数量" prop="goodsNumber">
            <el-input
              v-model="form.goodsNumber"
              placeholder="请输入销售数量"
              type="number"
            />
          </el-form-item>
          <el-form-item label="批次量/次" prop="batchNum">
            <el-input
              v-model="form.batchNum"
              placeholder="请输入每次交货的批次量"
              :maxlength="11"
              type="number"
            ></el-input>
          </el-form-item>
          <el-form-item label="信息大图" prop="infoPicUrl">
            <minio-image-upload
              v-model="form.infoPicUrl"
              :limit="1"
              :fileSize="50"
              accept="image/*,video/*"
              :fileType="['png', 'jpg', 'jpeg', 'mp4', 'avi']"
              :extraTips="form.infoType === 1 ? '轮播图尺寸： 1920 * 620' : ''"
            />
          </el-form-item>
          <template v-if="form.goodsType === 1">
            <el-form-item label="信息过期时间" prop="expireTime">
              <el-date-picker
                v-model="form.expireTime"
                type="datetime"
                placeholder="请选择信息过期时间"
                format="yyyy-MM-dd HH:mm:ss"
                :value-format="'yyyy-MM-dd HH:mm:ss'"
              ></el-date-picker>
            </el-form-item>
          </template>
          <template v-if="form.goodsType === 2">
            <el-form-item label="到货时间" prop="arriveTime">
              <el-date-picker
                v-model="form.arriveTime"
                type="datetime"
                placeholder="请选择到货时间"
                format="yyyy-MM-dd HH:mm:ss"
                :value-format="'yyyy-MM-dd HH:mm:ss'"
              ></el-date-picker>
            </el-form-item>
          </template>
          <el-form-item label="联系人" prop="contactUser">
            <el-input v-model="form.contactUser" placeholder="请输入联系人" />
          </el-form-item>
          <el-form-item label="联系电话" prop="contactUserMobile">
            <el-input v-model="form.contactUserMobile" placeholder="请输入联系电话" />
          </el-form-item>
          <el-form-item label="交付地点" prop="goodsAddress">
            <el-input v-model="form.goodsAddress" placeholder="请输入交付地点" />
          </el-form-item>
        </template>
        <template v-if="!isYingjian">
          <el-form-item label="可租时间-起" prop="supplyBegin">
            <el-date-picker
              clearable
              v-model="form.supplyBegin"
              type="date"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="请选择可租时间-起"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="可租时间-止" prop="supplyEnd">
            <el-date-picker
              clearable
              v-model="form.supplyEnd"
              type="date"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="请选择可租时间-止"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="上架截止时间" prop="deadTime">
            <el-date-picker
              clearable
              v-model="form.deadTime"
              type="date"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="请选择上架截止时间"
            >
            </el-date-picker>
          </el-form-item>
        </template>

        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="form.remark"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listSupply,
  getSupply,
  delSupply,
  addSupply,
  updateSupply,
  toggleSupply,
  toggleSupplyIsTop,
} from "@/api/system/supply";

import provinceMixin from "../mixin/province";
import companyMixin from "@/mixins/company";
import {updateStatusGoods} from "@/api/info/hardware";

export default {
  name: "Supply",
  props: {
    type: {
      type: Number,
    },
  },
  mixins: [provinceMixin, companyMixin],
  dicts: [
    "operator",
    "power_way",
    "route_type",
    "gpu_resource_type",
    "supply_gpu_type",
    "frame_price_unit",
    "bw_price_unit",
    "gpu_price_unit",
    "goods_price_unit",
  ],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 供应信息表格数据
      supplyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 算力-适用场景时间范围
      daterangeDeadTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        keyword: null,
        supplyTitle: null,
        supplyDesc: null,
        supplyType: null,
        cityName: null,
        framePowerWay: null,
        deadTime: null,
        auditStatus: null,
        status: null,
        bwOperator: null,
        bwRouteType: null,
        gpuAbilityType: null,
        gpuResource: null,
        gpuNet: null,
        gpuOccasion: null,
      },
      // 表单参数
      form: {
        orderNum: null,
      },
      // 表单校验
      rules: {
        supplyType: [{ required: true, message: "请选择供应类型" }],
        supplyTitle: [{ required: true, message: "请输入供应标题" }],
        supplyDesc: [{ required: true, message: "请输入供应描述" }],
        provinceArr: [{ required: true, type: "array", message: "请选择省市" }],
        framePowerWay: [{ required: true, message: "请选择供电方式" }],
        framePower: [{ required: true, message: "请输入机柜功率" }],
        frameHeight: [{ required: true, message: "请输入机柜高度" }],
        framePrice: [{ required: true, message: "请输入单价" }],
        supplyNum: [{ required: true, message: "请输入数量" }],
        bwOperator: [{ required: true, message: "请选择运营商" }],
        bwRouteType: [{ required: true, message: "请选择路由类型" }],
        bwBandwidthPrice: [{ required: true, message: "请输入带宽价格" }],
        bwBandwidthNum: [{ required: true, message: "请输入带宽数量" }],
        bwIpPrice: [{ required: true, message: "请输入IP价格" }],
        bwIpNum: [{ required: true, message: "请输入可租数量" }],
        gpuApplyPflops: [{ required: true, message: "请输入可租算力" }],
        gpuResource: [{ required: true, message: "请选择计算资源" }],
        gpuNet: [{ required: true, message: "请输入网络架构" }],
        gpuAbilityType: [{ required: true, message: "请选择计费模式" }],
        gpuNum: [{ required: true, message: "请输入可租数量" }],
        gpuPrice: [{ required: true, message: "请输入卡价格" }],
        gpuType: [{ required: true, message: "请选择卡类型" }],
        gpuOccasion: [{ required: true, message: "请输入适用场景" }],
        supplyBegin: [{ required: true, message: "请选择申请开始时间" }],
        supplyEnd: [{ required: true, message: "请选择申请结束时间" }],
        deadTime: [{ required: true, message: "请选择供应有效时间" }],
        brandName: [{ required: true, message: "请输入品牌" }],
        modelName: [{ required: true, message: "请输入型号" }],
        infoPicUrl: [{ required: true, message: "请上传货物图片" }],
        goodsType: [{ required: true, message: "请选择货源性质" }],
        goodsNumber: [{ required: true, message: "请输入销售数量" }],
        contactUser: [{ required: true, message: "请输入联系人" }],
        contactUserMobile: [{ required: true, message: "请输入联系方式" }],
        goodsPrice: [{ required: true, message: "请输入价格" }],
      },
    };
  },
  computed: {
    isJigui() {
      return this.type === 1;
    },
    isDaikuan() {
      return this.type === 2;
    },
    isSuanli() {
      return this.type === 4;
    },
    isYingjian() {
      return this.type === 5;
    },
  },
  created() {
    this.getCompanyList();
    this.getList();
  },
  methods: {
    async toggleStatus(row) {
      const { id, status } = row;
      const { code } = await toggleSupply({
        id,
        status: Number(!status),
      });
      if (code === 200) {
        this.$message.success(status ? "下架成功" : "上架成功");
        this.$set(row, "status", Number(!status));
      }
    },
    formatGoodsType(row, column, cellValue, index) {
      switch (cellValue) {
        case 1:
          return '现货';
        case 2:
          return '期货';
        default:
          return '未知';
      }
    },
    /** 查询供应信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeDeadTime && "" != this.daterangeDeadTime) {
        this.queryParams.params["beginDeadTime"] = this.daterangeDeadTime[0];
        this.queryParams.params["endDeadTime"] = this.daterangeDeadTime[1];
      }
      listSupply({
        ...this.queryParams,
        supplyType: this.type,
      }).then((response) => {
        this.supplyList = response.data;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        supplyTitle: null,
        supplyDesc: null,
        supplyType: null,
        cityName: null,
        framePowerWay: null,
        framePower: null,
        frameHeight: null,
        framePrice: null,
        supplyNum: null,
        supplyBegin: null,
        supplyEnd: null,
        deadTime: null,
        auditStatus: null,
        status: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        bwOperator: null,
        bwRouteType: null,
        bwBandwidthPrice: null,
        bwBandwidthNum: null,
        bwIpPrice: null,
        bwIpNum: null,
        gpuAbilityType: null,
        gpuApplyPflops: null,
        gpuResource: null,
        gpuNet: null,
        gpuNum: null,
        gpuOccasion: null,
        orderNum: null,
        brandName: null,
        modelName: null,
        infoPicUrl: null,
        goodsType: null,
        goodsNumber: null,
        contactUser: null,
        contactUserMobile: null,
        goodsPrice: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeDeadTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加供应信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getSupply(id).then((response) => {
        this.form = response.data;
        this.form.provinceArr = [
          response.data.provinceName,
          response.data.cityName,
        ];
        this.open = true;
        this.title = "修改供应信息";
      });
    },
    async handleToggleIsTop(row) {
      await this.$confirm(
        `确定${row.recommendStatus ? "取消置顶" : "置顶"}该数据吗？`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      );
      await toggleSupplyIsTop({
        id: row.id,
        status: Number(!row.recommendStatus),
      });
      this.$message.success(`${row.recommendStatus ? "取消置顶" : "置顶"}成功`);
      this.getList();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          const submitData = {
            ...this.form,
            provinceName: this.form.provinceArr[0],
            cityName: this.form.provinceArr[1],
            supplyType: this.type,
          };
          if (this.form.id != null) {
            updateSupply(submitData).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSupply(submitData).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除供应信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delSupply(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/supply/export",
        {
          ...this.queryParams,
        },
        `supply_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
